---
title: Rock, Paper, Scissors
---

How do you play rock, paper, scissors against an AI without letting it cheat?

This example uses a private conversation with a dedicated "Helper" agent to collect the user's move in secret. Only after both the user's and AI's choices are made do we reveal the user's choice to the AI to determine the winner.


```python
import controlflow as cf

# Create an agent to privately collect the user's score

user_helper = cf.Agent(
    "RPS Helper",
    instructions="""
        Get the user's choice of rock, paper, or scissors. 
        You can assure them that you won't share their answer 
        with the AI opponent.
        """,
)

# Create tasks for getting the user's choice, 
# the AI's choice, and reporting the score

@cf.task(interactive=True, agents=[user_helper])
def get_user_choice() -> ["rock", "paper", "scissors"]:
    """Ask the user to choose rock, paper, or scissors."""

@cf.task
def get_ai_choice() -> ["rock", "paper", "scissors"]:
    """Choose rock paper or scissors"""

@cf.task(interactive=True)
def report_score(user_choice, ai_choice) -> bool:
    """
    Tell the user if they won, the overall score, 
    then find out if they want to play again.
    """

@cf.flow
def rock_paper_scissors():
    keep_playing = True

    # keep playing as long as the user wants
    while keep_playing:
        
        # use a nested flow to keep the user's choice private
        with cf.Flow():
            user_choice = get_user_choice()

        # get the ai's choice
        ai_choice = get_ai_choice()

        # report the score and ask if the user wants to play again
        keep_playing = report_score(user_choice, ai_choice)

if __name__ == "__main__":
    rock_paper_scissors()
````